//
//  KKChatSendTextVC.m
//  DoMi
//
//  Created by 康凯 on 2016/12/19.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKChatSendTextVC.h"
#import "KKComHttp.h"
#import "KKChatSendSuccessDialog.h"

@interface KKChatSendTextVC ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;
@property (weak, nonatomic) IBOutlet UITextView *inputContent;
@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UILabel *nickname;
@property (weak, nonatomic) IBOutlet UILabel *company;

@end

@implementation KKChatSendTextVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden=NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.inputContent.delegate=self;
    self.inputContent.textColor=[UIColor blackColor];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backClick:)];
    [self.backView addGestureRecognizer:tap];
    self.company.text=self.expertCompany;
    self.nickname.text=self.expertName;
}
- (IBAction)sendClick:(id)sender {
    if([self.inputContent.text isEqualToString:@"请输入咨询内容"]){
        [self toast:@"请输入咨询内容"];
        return;
    }
    [self.view endEditing:YES];
    KKChatSendSuccessDialog *dialog=[[[NSBundle mainBundle] loadNibNamed:@"KKChatSendSuccessDialog" owner:self options:nil] lastObject];
    dialog.confirmClickBlock=^(){
        [self adviceToExpert];
    };
    [dialog show];
    
}
#pragma mark 按钮--返回
- (IBAction)backClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark textfiled代理
-(void)textViewDidBeginEditing:(UITextView *)textView{
    if([textView.text isEqualToString:@"请输入咨询内容"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if(textView.text.length < 1){
        textView.text = @"请输入咨询内容";
        textView.textColor = [UIColor grayColor];
    }
}

#pragma mark 接口--咨询专家
-(void)adviceToExpert{
    NSDictionary *params=@{UID_KEY:UID,TOKEN_KEY:TOKEN,@"asktype":@"0",@"question":self.inputContent.text,@"expertid":self.expertId};
    [KKComHttp adviceToExpert:params success:^(id data) {
        self.sendSuccessBlock();
        [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSError *error) {
        
    }];
}

@end
